//----------------------------------------------------------------------------------------
// @Project Includes
#include "includes.h"

//----------------------------------------------------------------------------------------
// @Local Macro Define in the module

//----------------------------------------------------------------------------------------
// @Local Type defines in the module

//----------------------------------------------------------------------------------------
// @Global Variables define in the module

//----------------------------------------------------------------------------------------
// @Prototypes of functions in the module
static void app_task_1000ms_trigger(void);
static void app_task_500ms_trigger(void);
static void app_task_250ms_trigger(void);
static void app_task_10ms_trigger(void);
static void app_task_realtime_trigger(void);

static stc_task_components_t TaskComps[] =
{
    {true, 0, 0, app_task_realtime_trigger},
		{false, 1, 1, app_task_10ms_trigger},
    {false, 5, 5, app_task_250ms_trigger},
    {false, 50, 50, app_task_500ms_trigger},
    {false, 100, 100, app_task_1000ms_trigger},
};
//----------------------------------------------------------------------------------------
/**
 * @brief  1000ms trigger function
 * @param  none
 * @return none
 * @note   none
 */
static void app_task_1000ms_trigger(void)
{
    drv_wdg_feed();
		LED_TOGGLE();
		app_afe_startBalance();
		srv_sh3673520_timeout();
		srv_event_timeout();
		drv_debug_var();
		drv_adc_dataRefresh();
		app_sleep_check();
}

/**
 * @brief  500ms trigger function
 * @param  none
 * @return none
 * @note   none
 */
static void app_task_500ms_trigger(void)
{
    app_soc_task();
}

/**
 * @brief  250ms trigger function
 * @param  none
 * @return none
 * @note   none
 */
static void app_task_250ms_trigger(void)
{
    app_afe_readAllRam();
}

/**
 * @brief  10ms trigger function
 * @param  none
 * @return none
 * @note   none
 */
static void app_task_10ms_trigger(void)
{
		drv_usart_timeout();
    srv_parm_changeCheck();
    srv_signal_updateActive();
		app_state_update();	
		app_protect_check();
}


/**
 * @brief  1ms trigger function
 * @param  none
 * @return none
 * @note   none
 */
static void app_task_realtime_trigger(void)
{
		srv_cosm_receiveProcess();
		srv_can_task();
}

/**
 * @brief  task time count
 * @param  none
 * @return none
 * @note   none
 */
void app_task_timecount(void)
{
    uint8_t i;
	
    for (i = 0; i < TASKS_LIST_MAX; i++)
    {
        if (TaskComps[i].Timer)
        {
            TaskComps[i].Timer--;
            if (TaskComps[i].Timer == 0)
            {
                TaskComps[i].Timer = TaskComps[i].ItvTime;
                TaskComps[i].RunState = true;
            }
        }
    }
}

/**
 * @brief  app task
 * @param  none
 * @return none
 * @note   none
 */
void app_task(void)
{
    uint8_t i;
    for (i = 0; i< TASKS_LIST_MAX; i++)
    {
        if (TaskComps[i].RunState)
        {
            TaskComps[i].TaskHook();
						TaskComps[i].RunState = false;
        }
        if (i == TAST_LIST_REALTIME)
        {
            TaskComps[i].RunState = true;   
        }
    } 
}


// =======================================================================================
// End of file.
// =======================================================================================
